package atguigu.xiaoxiduilie.xiaofeizhe;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

public class Consumer {

	public static void main(String[] args) throws IOException, TimeoutException {
		
		ConnectionFactory factory = new ConnectionFactory();
		factory.setUsername("test");
		factory.setPassword("123");
		factory.setHost("10.16.152.203");
		Connection conn = factory.newConnection();
		Channel channel = conn.createChannel();
		
		String queue_name = "prod_jd_equip_warn_msg";
        channel.queueDeclare(queue_name, true, false, false, null);
        List<String> infos = new ArrayList<String>();
        DefaultConsumer defaultConsumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, 
            		Envelope envelope, 
            		AMQP.BasicProperties properties, 
            		byte[] body)
                    throws IOException {
                String str = new String(body, "utf-8");
                infos.add(str);
                
                System.out.println(str);
            }
        };
        channel.basicConsume(queue_name, true, defaultConsumer);

	}
}
